<template>
	<view class="containerbox">
		<uv-navbar auto-back title="学习情况评价" placeholder />
		
		<view class="containerbox">
			<view class="mx-30 border-bottom pb-25 mb-25">
				<view class="text-44 comment_tirte font-600 my-20">{{ info.startTime }}</view>
				<view class="comment_tip text-qgray text-28 mb-10">{{ info.course?.name }}</view>
				<view class="comment_tip text-qgray text-28 flex-between flex-wrap">
					<text class="mb-10">助教：{{ info.teacher?.name }}</text>
					<text class="mb-10">学生：{{ info.user?.name }}</text>
					<text>累计识词：{{ info.totalWords }}</text>
					<text>学时：{{ info.wrongNumber }}</text>
				</view>
			</view>
			
			<view class="mx-30 mt-30">
				<view class="flex items-center">
					<text class="mr-30 text-30 title">评星</text>
					<uni-rate 
						custom-prefix="iconfont-rate icon-rate" 
						active-color="#0B9AFF" 
						v-model="params.userReputation" 
						margin="5"
					/> 
				</view>
				
				<view class="mt-30 border-bottom">
					<view class="text-30 title">评价内容</view>
					<fui-textarea 
						placeholder="请输入" 
						counter-size="24" 
						is-counter 
						v-model="params.userComment" 
						:border-top="false"
						border-color="#F0F2F4"
						:border-bottom="false"
						:padding="['10rpx', '0']"
						size="26"
					/>
				</view>
			</view>
		</view>
		
		<view class="px-30 py-30 border-top">
			<fui-button text="评论" @click="onConfirm" />
		</view>
	</view>
</template>

<script setup>
	
	import { onLoad } from "@dcloudio/uni-app"
	import { reactive, ref } from 'vue'
	import { imgPath } from '@/common/config'
	import { getlearnInfo, learnComment } from '@/common/apis/record'
	
	const params = reactive({
		id: '',
		userReputation: 1,
		userComment: ''
	})
	
	const info = ref({})
	
	function useVerify() {
		return new Promise((resolve, jeject) => {
			if (params.userComment.length <= 0) {
				uni.$fui.toast('请输入评论内容～')
				jeject()
			} else resolve()
		})
	}
	
	async function onConfirm() {
		await useVerify()
		await learnComment(params)
		uni.navigateBack()
		uni.setStorageSync('subscribeId', params.id)
		uni.$fui.toast('评论成功')
	}
	
	onLoad(async opt => {
		params.id = opt.id
		info.value = await getlearnInfo({ id: opt.id })
	})
	
</script>

<style>page{background-color: #fff}</style>
<style scoped lang="scss">
	.comment_tirte{color: #3A3F5E}
	.comment_tip text{width: 50%}
	.title{color: #1A1A1A}
</style>